package bgu.eliav;

import java.util.HashMap;
import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class SearchUser extends Activity {
	List<HashMap<String, String>> strList;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		final Activity searchUser = this;
		setContentView(R.layout.search_user);

		Button SearchButton = (Button) this.findViewById(R.id.SearchButton);
		SearchButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				// search the user in the dataBase

				EditText editName = (EditText) findViewById(R.id.EditSearchName);
				String name = editName.getText().toString();
				DatabaseExample db = DatabaseExample.getInstance(searchUser);
				db.open();
				Cursor c = db.getContactByName(name);
				if (c.moveToFirst()) {

					String Rname = c.getString(1);
					String userId = c.getString(2);
					String address = c.getString(3);
					String phone = c.getString(4);
					String bdate = c.getString(5);
					db.close();
					User resUser= new User(Rname, userId, phone, address, bdate);
					Intent intent = new Intent(searchUser, ViewItem.class);
					intent.putExtra("bgu.eliav.extra", resUser);
					startActivity(intent);
				} // end if
				
			} // end on click
		}); // end annon

	} // end on create

	public void onResume() {
		super.onResume();
	}
}
